import { BASE_URL, TIME_OUT } from "./config";
import HYRequest from "./request/index";

const hyRequest1 = new HYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
});

export const hyRequest2 = new HYRequest({
  baseURL: "http://codercba.com:1888/airbnb/api",
  timeout: 8000,

  interceptors: {
    requestInterceptors: function (config) {
      console.log("爱李芸成功请求成功拦截");
      return config;
    },
    requestInterceptorsCatch: function (err) {
      console.log("爱李芸成功请求失败拦截");
      return err;
    },
    responseInterceptors: function (res) {
      console.log("爱李芸响应成功请求成功拦截");
      return res;
    },
    responseInterceptorsCatch: function (err) {
      console.log("爱李芸响应失败请求成功拦截");
      return err;
    },
  },
});

// 取消请求
export const cancelRequest = (url: string | string[]) => {
  return hyRequest2.cancelRequest(url);
};
// 取消全部请求
export const cancelAllRequest = () => {
  return hyRequest2.cancelAllRequest();
};

export default hyRequest1;
